# -*- coding:utf-8 -*-
import time
from selenium.webdriver.support.ui import WebDriverWait
from Doctor_way.Register import RegisterDoctor
from Public_way.AutoTestLog import Logger


class Code_Login():
    def __init__(self, driver):
        self.driver = driver

    def Cancel_Diglog(self):
        time.sleep(2)
        self.driver.tap([(867, 482)], 500)
        logger2 = Logger()
        logger2.log(u'患者端-取消个人中心的活动图标')

    def LoginC(self, Name, Phone, Code):
        self.Cancel_Diglog()
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/iv_now_go_login')).click()
        # 选择环境
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/switch_server')).click()
        WebDriverWait(self.driver, 500).until(lambda x: x.find_element_by_name(Name)).click()
        logger2 = Logger()
        logger2.log(u'患者端-我点的是Test环境')
        # self.Cancel_Diglog()
        # WebDriverWait(self.driver, 500).until(
        #     lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/iv_now_go_login')).click()
        time.sleep(2)
        self.driver.tap([(528, 993)], 500)
        time.sleep(2)
        self.driver.tap([(524, 1704)], 500)
        # 输入手机号
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/et_input_phone_number')).send_keys(Phone)
        logger2.log(u'患者端-手机号输入完成')
        # 获取验证码
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_get_verfication_code')).click()
        logger2.log(u'患者端-获取验证码')
        # 输入验证码
        self.Ucode(Code)
        # 进入活动
        time.sleep(2)
        logger2.log(u'患者端-进入活动界面')
        self.driver.tap([(524, 1704)], 500)

    def UserData(self, Name, IDCard):
        logger2 = Logger()
        time.sleep(2)
        self.driver.tap([(528, 993)], 500)
        # 输入姓名
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/et_real_name_auth_name')).send_keys(Name)
        logger2.log(u'患者端-身份信息-输入名字完成')
        # 输入身份证
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/et_id_card')).send_keys(IDCard)
        logger2.log(u'患者端-身份信息-输入身份证完成')
        # 下一步添加
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_identity_info_next')).click()
        logger2.log(u'患者端-身份信息输入完成，进入下一步')

    def BandCard(self, BandCard, BandPhone, Code):
        # 提升安全等级
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_negative')).click()
        # 点击银行实名认证
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/rl_bank_card_auth')).click()
        # 输入银行卡号
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_real_name_auth_card_id')).send_keys(
            BandCard)
        # 输入预留手机号
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/et_real_name_auth_phone')).send_keys(
            BandPhone)
        # 点击下一步提交
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_bank_info_next')).click()
        # 输入验证码
        self.Ucode(Code)

        print '银行卡认证完成-来到个人中心页面-查看实名状态'
        # 点击头像
        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/iv_not_verified_avater')).click()

        status = self.driver.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_name_verity_status_text')

        print '用户实名状态为 %s' % status.text.encode('utf-8')

        WebDriverWait(self.driver, 500).until(
            lambda x: x.find_element_by_id('com.jkgj.skymonkey.patient:id/iv_name_verity_status_icon')).click()

        statusLevel = self.driver.find_element_by_id('com.jkgj.skymonkey.patient:id/tv_jk_account_number')

        print '用户实名等级为 %s' % statusLevel.text.encode('utf-8')

    def Ucode(self, code):
        logger2 = Logger()
        time.sleep(6)
        # 输入验证码
        for i in code:
            if i == '0':
                self.driver.tap([(537, 1847)], 500)
            elif i == '1':
                self.driver.tap([(186, 1362)], 500)
            elif i == '2':
                self.driver.tap([(537, 1362)], 500)
            elif i == '3':
                self.driver.tap([(903, 1362)], 500)
            elif i == '4':
                self.driver.tap([(182, 1515)], 500)
            elif i == '5':
                self.driver.tap([(541, 1515)], 500)
            elif i == '6':
                self.driver.tap([(897, 1515)], 500)
            elif i == '7':
                self.driver.tap([(180, 1676)], 500)
            elif i == '8':
                self.driver.tap([(549, 1676)], 500)
            elif i == '9':
                self.driver.tap([(906, 1676)], 500)
            logger2.log(u'验证码输入完成')
